﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AsyncCompletedEventArgs.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   A  that supports a single typed .
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.ComponentModel
{
    using System;
    using System.ComponentModel;

    /// <summary>
    /// A <see cref="AsyncCompletedEventArgs"/> that supports a single typed <see cref="Result"/>.
    /// </summary>
    /// <typeparam name="T">The type of the <see cref="Result"/>.</typeparam>
    public class AsyncCompletedEventArgs<T> : AsyncCompletedEventArgs
    {
        #region Fields

        private T _result;

        #endregion

        public AsyncCompletedEventArgs(T result, Exception error, bool cancelled, object userState) : base(error, cancelled, userState)
        {
            Result = result;
        }

        /// <summary>
        /// Gets the result of the operation.
        /// </summary>
        /// <value>The result.</value>
        public T Result
        {
            get
            {
                RaiseExceptionIfNecessary();
                return _result;
            }
            private set
            {
                _result = value;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance has a result.
        /// </summary>
        /// <value><c>true</c> if this instance has a result; otherwise, <c>false</c>.</value>
        public bool HasResult
        {
            get { return Error == null && !Cancelled; }
        }
    }
}
